
/*
 * servo.c
 *
 * Created: 11/6/2013 11:45:38 AM
 *  Author: Daniel Keith
 */ 
#include <avr/io.h>
#include <avr/interrupt.h>
#include "util.h"
#include <stdio.h>

static int pulse_width; 
static int TOP = 21501;


/** initializes the servo
*	initializes the servo to be used
*/
void init_ser(){
	unsigned pulse_period = TOP+1;
	OCR3A = pulse_period-1;
	OCR3B = pulse_width -1;
	TCCR3A = 0b00100011;
	TCCR3B = 0b00011010;  //prescaler of 8 is 010
	DDRE |= _BV(4);
}

/** moves the servo
*	moves the servo by changing the output waveform
*	@param servo the distance the servo needs to move
*/
void move_servo(float servo){
	//	int zero = 800;  //0 degrees = 800
	//	int max = 4400;// robot 3   180 degrees = 4400  midpoint = 2600
	//	int servo = (degrees/180)*(max-zero)+zero;
	float range = 4800 - 1300;
	float one = range/180;
	servo = (one*servo);
	OCR3B = (int)servo;
	
}